
<!DOCTYPE HTML>
<html>
<head>
    <title>login</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="__STATIC__/css/style.css" rel="stylesheet" type="text/css" media="all"/>
    <link rel="stylesheet" href="__STATIC__/plugins/layui/css/layui.css" media="all">
</head>
<body>
<div class="login">
    <div class="login-top">
        <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">选择</label>
            <div class="layui-input-block">
                <select name="parent" lay-filter="parent" lay-verify="required">
                    <option value="">---选择---</option>
                    {foreach $naire.category as $c}
                    <option value="{$c.name}">{$c.name}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        {foreach $naire.category as $c}
        <div class="layui-form-item children" id="{$c.name}" style="display: none">
            <label class="layui-form-label">选择</label>
            <div class="layui-input-block">
                <select>
                    <option value="">---选择---</option>
                    {foreach $c.children as $s}
                    <option value="{$s}">{$s}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        {/foreach}
        <div class="layui-form-item">
            <div class=" forgot"></div>
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="demo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    </div>
</div>
<script src="__STATIC__/plugins/layui/layui.js"></script>
<script>
    layui.use(['form','layer'], function () {
        var form=layui.form;
        var layer=layui.layer;
        window.$=layui.$;
        form.on('select(parent)',function(data){
            var value=data.value;
            $('#'+value).siblings('.children').hide()
                .find('select').attr('readonly','readonly').removeAttr('name').removeAttr('lay-verify')
                .end().end().show().find('select').removeAttr('readonly').attr('name','children').attr('lay-verify',"required")
        });
        form.on('submit(demo)', function(){
            $.post("{:url('answer/choose')}",$('form').serialize(),function(response){
                layer.msg(response.msg);
                if(response.code==0){
                    setTimeout(function(){
                        location.href="{:url('answer/answer',['id'=>$naire.id])}";
                    },1000);
                }
            });
            return false;
        });
    });
</script>
</body>
</html>